<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <style>
      * {
        padding: 0;
        margin: 0;
      }

      .box1 {
        border: 1px solid red;
      }
      .box2 {
        width: 300px;
        height: 300px;
        background-color: salmon;
        float: left;
      }

      /* .box3{
            clear: both;
        } */

/* 这种写法不仅可以防止父元素的坍塌，还能解决子父元素的外边距重叠问题 */
      .clearfix::before,
      .clearfix::after {
          content: '';
          display: table;
          clear: both;

      }

      .box4 {
        width: 300px;
        height: 300px;
        background-color: cadetblue;
      }
    </style>
  </head>
  <body>
    <div class="box1 clearfix">
      <div class="box2"></div>
      <div class="box3"></div>
    </div>
    <div class="box4"></div>
  </body>
</html>
